package com.zhuhjay.system.factory.entity;

import com.zhuhjay.common.utils.ClientUtils;
import com.zhuhjay.system.domain.entity.OperatorLog;

import java.util.Date;

/**
 * OperatorLog实体类的构建工厂
 * @author ZhuHJay
 * @date 2022/3/30 19:30
 */
public class OperatorLogBuilderFactory {

    private final OperatorLog operatorLog;

    /** 实例化构建工厂的bean **/
    public OperatorLogBuilderFactory(){
        operatorLog = new OperatorLog();
    }

    /** 处理方法名 **/
    public OperatorLogBuilderFactory methodName(String methodName){
        operatorLog.setMethodName(methodName);
        return this;
    }

    /** 方法描述 **/
    public OperatorLogBuilderFactory methodDesc(String methodDesc){
        operatorLog.setMethodDesc(methodDesc);
        return this;
    }

    /** 请求方式 **/
    public OperatorLogBuilderFactory requestMethod(String requestMethod){
        operatorLog.setRequestMethod(requestMethod);
        return this;
    }

    /** 操作人 **/
    public OperatorLogBuilderFactory operName(String operName){
        operatorLog.setOperName(operName);
        return this;
    }

    /** 请求url **/
    public OperatorLogBuilderFactory operUrl(String operUrl){
        operatorLog.setOperUrl(operUrl);
        return this;
    }

    /** 请求ip及生成地理位置 **/
    public OperatorLogBuilderFactory operIpAndLocation(String operIp){
        operatorLog.setOperIp(operIp);
        operatorLog.setOperLocation(ClientUtils.getCityInfo(operIp));
        return this;
    }

    /** 请求参数 **/
    public OperatorLogBuilderFactory operParam(String operParam){
        operatorLog.setOperParam(operParam);
        return this;
    }

    /** 请求响应 **/
    public OperatorLogBuilderFactory operResult(String operResult){
        operatorLog.setOperResult(operResult);
        return this;
    }

    /** 请求状态: 0失败 1成功 **/
    public OperatorLogBuilderFactory status(Integer status){
        operatorLog.setStatus(status);
        return this;
    }

    /** 错误信息 **/
    public OperatorLogBuilderFactory errorMsg(String errorMsg){
        operatorLog.setErrorMsg(errorMsg);
        return this;
    }

    /** 将构建的bean返回 **/
    public OperatorLog build(){
        // 生成操作时间
        operatorLog.setOperTime(new Date());
        return operatorLog;
    }

}
